package deep.projects.newsapp.activities;

import android.os.Bundle;
import android.support.v7.widget.SwitchCompat;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import com.wuxinwudai.android.util.FileUtils;
import com.wuxinwudai.android.util.SharedPreferencesUtils;
import com.wuxinwudai.android.util.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;
import deep.projects.newsapp.R;
import deep.projects.newsapp.app.NewsApplication;
import deep.projects.newsapp.app.Preferences;
import deep.projects.newsapp.utils.ViewUtils;

/**
 * @author 吾心无待 于2016年03月05日
 */
public class SettingActivity extends BaseLayoutActivity {
    @BindView(R.id.tv_clean_cache) TextView tvCleanCache;
    @BindView(R.id.sc_jpush) SwitchCompat mscPushMessage;
    @BindView(R.id.sc_show_mode) SwitchCompat mscShowMode;
    @Override
    public int getLayoutId() {
        return R.layout.activity_settings;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        tvTitle.setText(R.string.title_activity_settings);
        tvCleanCache.setText(NewsApplication.getCacheSize(this));
        initPreferences();
    }

    //关于我们跳转
    @OnClick(R.id.ll_about)
    void onGoToAboutActivity() {
        ViewUtils.goAboutActivity(SettingActivity.this);
    }

    //意见反馈
    @OnClick(R.id.ll_feedback)
    void onGoToFeedbackActivity() {
        ViewUtils.goFeedbackActivity(SettingActivity.this);
    }

    //版本更新
    @OnClick(R.id.ll_version_update)
    void onVersionUpdate() { ViewUtils.goCheckVersionActivity(SettingActivity.this); }

    //清除缓存
    @OnClick(R.id.ll_clean_cache) void onCleanCache() {
        NewsApplication.clearCache(this);
        tvCleanCache.setText(NewsApplication.getCacheSize(this));
    }

    //消息推送
    @OnClick(R.id.ll_push_message)
    void onPushMessage() { SharedPreferencesUtils.putBoolean(Preferences.MESSAGE_NOTIFICATION,mscPushMessage.isChecked()); }

    //显示模式
    @OnClick(R.id.ll_mode)
    void onShowModeClick() { SharedPreferencesUtils.putBoolean(Preferences.NIGTH_MODE,mscShowMode.isChecked()); }

    private void initPreferences() {
        try {
            boolean isNightMode = SharedPreferencesUtils.getBoolean(Preferences.NIGTH_MODE, false);
            boolean messgeNotification = SharedPreferencesUtils.getBoolean(Preferences.MESSAGE_NOTIFICATION, false);
            mscPushMessage.setChecked(messgeNotification);//是否进行消息推送
            mscShowMode.setChecked(isNightMode);//是否为夜间模式
        } catch (Exception ex) {

        }
    }
}
